#!/bin/env python
# -*- coding:utf-8 -*-
# -------------------------------------------------------------------------------
# Filename:    upload_wp.py
# Revision:    1.1
# Date:        2012-4-10
# Author:      simon-zzm
# Email:       simon-zzm@163.com
# -------------------------------------------------------------------------------

import time
import xmlrpclib
 
def send_data_to_wp(wp_url,wp_username,wp_password,title,content,tags,classify):
    wp_blogid=''
    status_published = 0
    server = xmlrpclib.ServerProxy(wp_url)
    categories = ["%s"%classify]
    data = {'title': title, 
            'description': content, 
            'categories': categories, 
            'mt_keywords': tags,
            'post_status':'publish'}
    print data
    post_id = server.metaWeblog.newPost(wp_blogid, wp_username, wp_password, data, status_published)
    return post_id

def main():
    wp_url = "http://www.simonzhang.net/xmlrpc.php" 
    wp_username = "grabproxy" 
    wp_password = "xxxxxx"
    wp_tags = ["代理地址","代理列表","proxy list"]
    now_date = time.strftime("%Y-%m-%d %H:%M",time.localtime(time.time()))
    wp_title= "代理地址 验证时间%s"%now_date
    f_content = open('test_ip.txt','rb').readlines()
    wp_content='<p>'
    for loop in f_content:
        wp_content=wp_content+"%s<br/>"%loop
    wp_content=wp_content+"</p>"
    wp_classify='免费代理'
    send_data_to_wp(wp_url,wp_username,wp_password,wp_title,wp_content,wp_tags,wp_classify)
    
if __name__ == '__main__':
    main()
